import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { UserItemService } from './user-item.service';
import { UserItem } from './entities/user-item.entity';
import { CreateUserItemDto } from './dto/create-user-item.dto';
import { PageQuery } from '../../../util/entity/page.entity';
import { UpdateUserItemDto } from './dto/update-user-item.dto';
import { ReqUser } from '../../../common/decorator/user.decorator';

@Controller()
export class UserItemController {
  constructor(private readonly userItemService: UserItemService) {}
  @Post()
  create(@Body() createUserItemDto: CreateUserItemDto) {
    return this.userItemService.create(createUserItemDto);
  }

  @Get('list')
  findAll(@ReqUser('id') userId: number) {
    return this.userItemService.findAll(userId);
  }
  @Post('list')
  findAllWithPage(@Body() pageQuery: PageQuery<UserItem>) {
    return this.userItemService.findAllWithPage(pageQuery);
  }

  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.userItemService.findOne(id);
  }

  @Patch(':id')
  update(
    @Param('id') id: number,
    @Body() updateUserItemDto: UpdateUserItemDto,
  ) {
    return this.userItemService.update(id, updateUserItemDto);
  }

  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.userItemService.remove(id);
  }
}
